#include "signup.h"
#include "ui_signup.h"
#include "mainwindow.h"

Signup::Signup(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Signup)
{
    ui->setupUi(this);
    QPixmap *pix = new QPixmap(":/mainphoto/zhuye.png");
    QSize sz = ui->label_image->size();
    ui->label_image->setPixmap(pix->scaled(sz));
}

Signup::~Signup()
{
    delete ui;
}

void Signup::on_pushButton_2_clicked()
{
    MainWindow *w = new MainWindow;
        w->show();
        this->close();
}

void Signup::on_pushButton_clicked()
{
    sqlite_Init();
    QString username = "none";
    QString password = "none";
    QString surepass = "none";
    username = ui->lineEdit_username->text();
    password = ui->lineEdit_passwd->text();
    surepass = ui->lineEdit_surepasswd->text();
        //判断密码是否一致
        if(password == surepass)
        {

            //例：insert into (数据库名称user) (表包含的字段username,password) values(填入内容)
            QString sql=QString("insert into user(username,password) values('%1','%2');")
                    .arg(username).arg(password);
            QSqlQuery query;

            //执行并判断query语句是否执行成功且用户名和密码是否为空
            if(!query.exec(sql)||username=="none"||password=="none"||surepass=="none")
            {
                qDebug()<<"insert into error";
                QMessageBox::information(this,"注册认证","注册失败！");
            }
            else
            {
                qDebug()<<"insert into success";
                QMessageBox::information(this,"注册认证","注册成功！");
                MainWindow *w = new MainWindow;
                w->show();
                this->close();
            }

        }else{
            QMessageBox::information(this,"注册认证","两次密码输入不一致");
        }
}
